/* Part of the KnowARC Janitor Use-case processor for taverna
 *  written 2007-2010 by Hajo Nils Krabbenhoeft and Steffen Moeller
 *  University of Luebeck, Institute for Neuro- and Bioinformatics
 *  University of Luebeck, Institute for Dermatolgy
 *
 *  This package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This package is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this package; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

package de.uni_luebeck.inb.knowarc.gui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;

import de.uni_luebeck.inb.knowarc.usecases.invocation.AskUserForPw;
import de.uni_luebeck.inb.knowarc.usecases.invocation.ssh.SshNode;
import de.uni_luebeck.inb.knowarc.usecases.invocation.ssh.SshUseCaseInvocation;

/**
 * please do not edit this class manually. only using the netbeans IDE 6.1 all
 * the functionality shall be stored in the KnowARCConfiguration class
 * 
 * @author fxtentacle
 */
public class KnowARCConfigurationDialog extends javax.swing.JDialog {
	private static final long serialVersionUID = 1L;

	private KnowARCConfiguration configuration;

	public KnowARCConfigurationDialog(java.awt.Frame parent, boolean modal, KnowARCConfiguration configuration) {
		super(parent, modal);

		this.configuration = configuration;
		DefaultListModel lm = new DefaultListModel();
		for (String cur : configuration.info.lGIIS) {
			lm.addElement(cur);
		}
		gridInfosystemListModel = lm;

		lm = new DefaultListModel();
		for (SshNode cur : configuration.sshWorkerNodes) {
			lm.addElement(cur.getHost());
		}
		sshNodesListModel = lm;

		initComponents();

		if (configuration.invocationMethod.equals("grid"))
			jRadioButton1.setSelected(true);
		else if (configuration.invocationMethod.equals("ssh"))
			jRadioButton2.setSelected(true);
		else if (configuration.invocationMethod.equals("local"))
			jRadioButton3.setSelected(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		invocationMethod = new javax.swing.ButtonGroup();
		jPanel12 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jRadioButton1 = new javax.swing.JRadioButton();
		jRadioButton2 = new javax.swing.JRadioButton();
		jRadioButton3 = new javax.swing.JRadioButton();
		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel1 = new javax.swing.JPanel();
		jTabbedPane2 = new javax.swing.JTabbedPane();
		jPanel11 = new javax.swing.JPanel();
		jPanel3 = new javax.swing.JPanel();
		jLabel2 = new javax.swing.JLabel();
		certificateIdentity = new javax.swing.JLabel();
		jButton1 = new javax.swing.JButton();
		jPanel4 = new javax.swing.JPanel();
		jLabel3 = new javax.swing.JLabel();
		caFilePath = new javax.swing.JLabel();
		jPanel5 = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		gridInfosystemList = new javax.swing.JList();
		jButton2 = new javax.swing.JButton();
		jLabel4 = new javax.swing.JLabel();
		newInfosystemUrl = new javax.swing.JTextField();
		jButton3 = new javax.swing.JButton();
		jPanel6 = new javax.swing.JPanel();
		jScrollPane2 = new javax.swing.JScrollPane();
		authorizedResources = new javax.swing.JTextPane();
		jButton4 = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jTabbedPane3 = new javax.swing.JTabbedPane();
		jPanel7 = new javax.swing.JPanel();
		jScrollPane3 = new javax.swing.JScrollPane();
		jList1 = new javax.swing.JList();
		jButton6 = new javax.swing.JButton();
		jPanel8 = new javax.swing.JPanel();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		jLabel9 = new javax.swing.JLabel();
		jLabel10 = new javax.swing.JLabel();
		jButton7 = new javax.swing.JButton();
		jButton8 = new javax.swing.JButton();
		sshHostname = new javax.swing.JTextField();
		sshPort = new javax.swing.JTextField(30);
		sshUser = new javax.swing.JTextField(30);
		sshDir = new javax.swing.JTextField(30);
		jLabel11 = new javax.swing.JLabel();
		sshKeyfile = new javax.swing.JTextField();
		sshPass = new javax.swing.JPasswordField();
		jButton10 = new javax.swing.JButton();
		jLabel13 = new javax.swing.JLabel();
		jLabel14 = new javax.swing.JLabel();
		jLabel12 = new javax.swing.JLabel();
		jLabel15 = new javax.swing.JLabel();
		jPanel9 = new javax.swing.JPanel();
		jPanel10 = new javax.swing.JPanel();
		jButton9 = new javax.swing.JButton();
		jScrollPane4 = new javax.swing.JScrollPane();
		jTextPane1 = new javax.swing.JTextPane();
		jButton5 = new javax.swing.JButton();
		jLabel5 = new javax.swing.JLabel();
		jComboBox1 = new javax.swing.JComboBox();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jPanel12.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));

		jLabel1.setText("Use case invokation method:   ");

		invocationMethod.add(jRadioButton1);
		jRadioButton1.setText("Grid");

		invocationMethod.add(jRadioButton2);
		jRadioButton2.setText("Ssh");

		invocationMethod.add(jRadioButton3);
		jRadioButton3.setText("Local");

		jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Grid proxy certificate"));

		jLabel2.setText("Identity:");

		certificateIdentity.setText(configuration.getCertificateIdentity());

		jButton1.setText("load");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				loadCertificate(evt);
			}
		});

		org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel3Layout.createSequentialGroup().addContainerGap().add(jLabel2).addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(
						certificateIdentity, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap()));
		jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel3Layout.createSequentialGroup().add(
						jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel2).add(certificateIdentity).add(jButton1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addContainerGap(
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("CA Certificates"));

		jLabel3.setText("Your certificate authority files should be installed into:");

		caFilePath.setText(configuration.getCAPath());

		org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
		jPanel4.setLayout(jPanel4Layout);
		jPanel4Layout.setHorizontalGroup(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				org.jdesktop.layout.GroupLayout.TRAILING,
				jPanel4Layout.createSequentialGroup().addContainerGap().add(
						jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING).add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE).add(org.jdesktop.layout.GroupLayout.LEADING, caFilePath,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)).addContainerGap()));
		jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel4Layout.createSequentialGroup().add(jLabel3).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(caFilePath).addContainerGap()));

		org.jdesktop.layout.GroupLayout jPanel11Layout = new org.jdesktop.layout.GroupLayout(jPanel11);
		jPanel11.setLayout(jPanel11Layout);
		jPanel11Layout.setHorizontalGroup(jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel11Layout.createSequentialGroup().addContainerGap().add(
						jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
		jPanel11Layout.setVerticalGroup(jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel11Layout.createSequentialGroup().addContainerGap().add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap(260, Short.MAX_VALUE)));

		jTabbedPane2.addTab("Proxy Certificate", jPanel11);

		jPanel5.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));

		gridInfosystemList.setModel(gridInfosystemListModel);
		jScrollPane1.setViewportView(gridInfosystemList);

		jButton2.setText("Delete selected");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteSelectedInfosystems(evt);
			}
		});

		jLabel4.setText("Enter a new URL, like ldap://gridsrv4.nbi.dk:2135/mds-vo-name=PGS,o=grid");

		newInfosystemUrl.setText("ldap://<host>:2135/mds-vo-name=local,o=grid");

		jButton3.setText("Add");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
		jPanel5.setLayout(jPanel5Layout);
		jPanel5Layout.setHorizontalGroup(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel5Layout.createSequentialGroup().addContainerGap().add(
						jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
								jPanel5Layout.createSequentialGroup().add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
										.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												177, Short.MAX_VALUE).addContainerGap()).add(
								jPanel5Layout.createSequentialGroup().add(newInfosystemUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
										.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												184, Short.MAX_VALUE).add(4, 4, 4)).add(
								jPanel5Layout.createSequentialGroup().add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE).add(4,
										4, 4)))));
		jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel5Layout.createSequentialGroup().add(
						jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jButton2).add(
								jPanel5Layout.createSequentialGroup().add(1, 1, 1).add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 355,
										Short.MAX_VALUE))).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel4).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(
						jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(newInfosystemUrl,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jButton3))));

		jTabbedPane2.addTab("Grid Information Systems", jPanel5);

		jPanel6.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));

		authorizedResources.setContentType("text/html");
		authorizedResources.setEditable(false);
		authorizedResources
				.setText("<html>\r\n  <head>\r\n\r\n  </head>\r\n  <body>\r\n    <p style=\"margin-top: 0\">\r\n      \rPlease click on the enumerate resources button.\n    </p>\r\n  </body>\r\n</html>\r\n");
		jScrollPane2.setViewportView(authorizedResources);

		jButton4.setText("Enumerate resources");
		jButton4.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton4ActionPerformed(evt);
			}
		});

		org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
		jPanel6.setLayout(jPanel6Layout);
		jPanel6Layout.setHorizontalGroup(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel6Layout.createSequentialGroup().addContainerGap().add(
						jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jScrollPane2,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE).add(jButton4)).addContainerGap()));
		jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				org.jdesktop.layout.GroupLayout.TRAILING,
				jPanel6Layout.createSequentialGroup().add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jButton4)));

		jTabbedPane2.addTab("Grid Resources", jPanel6);

		org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel1Layout.createSequentialGroup().addContainerGap().add(jTabbedPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE)
						.addContainerGap()));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel1Layout.createSequentialGroup().addContainerGap().add(jTabbedPane2).addContainerGap()));

		jTabbedPane1.addTab("Configure grid access", jPanel1);

		jList1.setModel(sshNodesListModel);
		jScrollPane3.setViewportView(jList1);

		jButton6.setText("Delete selected");
		jButton6.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteSshNodes(evt);
			}
		});

		org.jdesktop.layout.GroupLayout jPanel7Layout = new org.jdesktop.layout.GroupLayout(jPanel7);
		jPanel7.setLayout(jPanel7Layout);
		jPanel7Layout.setHorizontalGroup(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel7Layout.createSequentialGroup().addContainerGap().add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 337,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jButton6,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE).addContainerGap()));
		jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel7Layout.createSequentialGroup().add(
						jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
								jPanel7Layout.createSequentialGroup().add(12, 12, 12).add(jButton6)).add(
								jPanel7Layout.createSequentialGroup().addContainerGap().add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 340,
										Short.MAX_VALUE))).addContainerGap()));

		jTabbedPane3.addTab("Ssh worker nodes", jPanel7);

		jLabel6.setText("Hostname:");

		jLabel7.setText("Port:");

		jLabel8.setText("Username:");

		jLabel9.setText("Password:");

		jLabel10.setText("Directory:");

		jButton7.setText("Test");
		jButton7.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				testWorkerNode(evt);
			}
		});

		jButton8.setText("Add");
		jButton8.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addWorkerNode(evt);
			}
		});

		sshHostname.setText("localhost");

		sshPort.setText("22");

		sshDir.setText("/tmp");

		jLabel11.setText("Keyfile:");

		jButton10.setText("select");
		jButton10.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				selectKeyfile(evt);
			}
		});

		jLabel13.setText("Your password will NOT be stored. ");

		jLabel14.setText("Any credentials you enter here are only for testing.");

		jLabel12.setText("When invoking a workflow run, Taverna will ask you for your credentials.");

		jLabel15.setText("Taverna will also offer to store your credentials in its credential manager.");

		org.jdesktop.layout.GroupLayout jPanel8Layout = new org.jdesktop.layout.GroupLayout(jPanel8);
		jPanel8.setLayout(jPanel8Layout);
		jPanel8Layout.setHorizontalGroup(jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(
						jPanel8Layout.createSequentialGroup().addContainerGap()
								.add(
										jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
												jPanel8Layout.createSequentialGroup().add(jButton7).add(10, 10, 10).add(jButton8)).add(
												jPanel8Layout.createSequentialGroup().add(
														jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jLabel7).add(jLabel8)
																.add(jLabel6)).add(27, 27, 27).add(
														jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(sshHostname,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE).add(
																jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false).add(sshUser)
																		.add(sshPort)))).add(jLabel11).add(jLabel10).add(
												jPanel8Layout.createSequentialGroup().add(jLabel9).add(27, 27, 27).add(
														jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
																org.jdesktop.layout.GroupLayout.TRAILING,
																jPanel8Layout.createSequentialGroup().add(sshKeyfile,
																		org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE).addPreferredGap(
																		org.jdesktop.layout.LayoutStyle.RELATED).add(jButton10)).add(sshPass,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE).add(sshDir,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE))).add(jLabel13,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE).add(jLabel15,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE).add(jLabel14,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
												.add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 515,
														Short.MAX_VALUE)).addContainerGap()));
		jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel8Layout.createSequentialGroup().addContainerGap().add(
						jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel6).add(sshHostname,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
						jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel7).add(sshPort,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
						jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel8).add(sshUser,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel13)
						.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel14).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
								jLabel12).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jLabel15).addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED).add(
								jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel9).add(sshPass,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
								jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel11).add(jButton10).add(sshKeyfile,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
								jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel10).add(sshDir,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
										org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).add(
								jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
										jPanel8Layout.createSequentialGroup().addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 9, Short.MAX_VALUE).add(
												jButton8).addContainerGap()).add(
										jPanel8Layout.createSequentialGroup().addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(jButton7)
												.addContainerGap()))));

		jTabbedPane3.addTab("Add a new ssh worker node", jPanel8);

		org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel2Layout.createSequentialGroup().addContainerGap().add(jTabbedPane3).addContainerGap()));
		jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel2Layout.createSequentialGroup().addContainerGap().add(jTabbedPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap()));

		jTabbedPane1.addTab("Configure ssh invocation", jPanel2);

		jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Grid jobs submitted using the plugin"));

		jButton9.setText("Remove all submitted grid jobs and clean up their data");
		jButton9.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				removeAllGridJobs(evt);
			}
		});

		jTextPane1.setText(configuration.info.getHistory());
		jScrollPane4.setViewportView(jTextPane1);

		org.jdesktop.layout.GroupLayout jPanel10Layout = new org.jdesktop.layout.GroupLayout(jPanel10);
		jPanel10.setLayout(jPanel10Layout);
		jPanel10Layout.setHorizontalGroup(jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel10Layout.createSequentialGroup().addContainerGap().add(
						jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(org.jdesktop.layout.GroupLayout.TRAILING, jButton9)
								.add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE)).addContainerGap()));
		jPanel10Layout.setVerticalGroup(jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				org.jdesktop.layout.GroupLayout.TRAILING,
				jPanel10Layout.createSequentialGroup().add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.UNRELATED).add(jButton9).addContainerGap()));

		org.jdesktop.layout.GroupLayout jPanel9Layout = new org.jdesktop.layout.GroupLayout(jPanel9);
		jPanel9.setLayout(jPanel9Layout);
		jPanel9Layout.setHorizontalGroup(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel9Layout.createSequentialGroup().addContainerGap().add(jPanel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
		jPanel9Layout.setVerticalGroup(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel9Layout.createSequentialGroup().addContainerGap().add(jPanel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));

		jTabbedPane1.addTab("Submitted grid jobs", jPanel9);

		jButton5.setText("Save and close");
		jButton5.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				saveAndClose(evt);
			}
		});

		jLabel5.setText("Logging level:");

		jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Error", "Warning", "Information", "Debugging" }));
		jComboBox1.setSelectedIndex(configuration.debug);

		org.jdesktop.layout.GroupLayout jPanel12Layout = new org.jdesktop.layout.GroupLayout(jPanel12);
		jPanel12.setLayout(jPanel12Layout);
		jPanel12Layout.setHorizontalGroup(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel12Layout.createSequentialGroup().add(
						jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jLabel1).add(jLabel5)).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(
						jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jComboBox1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(
								jPanel12Layout.createSequentialGroup().add(jRadioButton1).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
										jRadioButton2).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jRadioButton3)))).add(
				jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING).add(jButton5).add(jTabbedPane1,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
		jPanel12Layout.setVerticalGroup(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel12Layout.createSequentialGroup().add(
						jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jRadioButton1).add(
								jRadioButton2).add(jRadioButton3)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(
						jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel5,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jComboBox1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addPreferredGap(
						org.jdesktop.layout.LayoutStyle.RELATED).add(jButton5)));

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jPanel12,
				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(
				layout.createSequentialGroup().add(jPanel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void loadCertificate(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_loadCertificate
		String r = configuration.chooseCertificate(this);
		certificateIdentity.setText(r);
		this.pack();
	}// GEN-LAST:event_loadCertificate

	private void deleteSelectedInfosystems(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSelectedInfosystems
		Object[] sel = gridInfosystemList.getSelectedValues();
		for (Object cur : sel) {
			gridInfosystemListModel.removeElement(cur);
			configuration.info.lGIIS.remove(cur);
		}
	}// GEN-LAST:event_deleteSelectedInfosystems

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton3ActionPerformed
		gridInfosystemListModel.addElement(newInfosystemUrl.getText());
		configuration.info.lGIIS.add(newInfosystemUrl.getText());
	}// GEN-LAST:event_jButton3ActionPerformed

	private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton4ActionPerformed
		authorizedResources.setText(configuration.updateGridQueues());
	}// GEN-LAST:event_jButton4ActionPerformed

	private void saveAndClose(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveAndClose
		new Thread(new Runnable() {
			public void run() {
				configuration.updateGridQueues();
			}
		}).start();
		if (jRadioButton1.isSelected())
			configuration.invocationMethod = "grid";
		if (jRadioButton2.isSelected())
			configuration.invocationMethod = "ssh";
		if (jRadioButton3.isSelected())
			configuration.invocationMethod = "local";
		configuration.debug = (byte) jComboBox1.getSelectedIndex();
		configuration.saveSshConfiguration();
		configuration.saveInvocationMethod();
		this.setVisible(false);
	}// GEN-LAST:event_saveAndClose

	private void deleteSshNodes(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSshNodes
		Object[] sel = jList1.getSelectedValues();
		List<SshNode> del = new ArrayList<SshNode>();
		for (Object cur : sel) {
			sshNodesListModel.removeElement(cur);
			for (SshNode curNode : configuration.sshWorkerNodes) {
				if (curNode.getHost().equals(cur))
					del.add(curNode);
			}
		}
		configuration.sshWorkerNodes.removeAll(del);
	}// GEN-LAST:event_deleteSshNodes

	private SshNode fillInSshNode() {
		SshNode node = new SshNode();
		node.setHost(sshHostname.getText());
		node.setPort(Integer.parseInt(sshPort.getText()));
		node.setDirectory(sshDir.getText());
		if (!node.getDirectory().endsWith("/"))
			node.setDirectory(node.getDirectory() + "/");
		return node;
	}

	private AskUserForPw fillInAskUser() {
		final String user = sshUser.getText();
		final String pass = new String(sshPass.getPassword());
		final String key = sshKeyfile.getText();
		return new AskUserForPw() {
			public void setSshNode(SshNode sshNode) {
			}

			public String getUsername() {
				return user;
			}

			public String getPassword() {
				return pass;
			}

			public String getPassphrase() {
				return AskUserForPwPopup.ask("Please enter your passphrase for " + key + " used for " + user, "Keyfile for " + user);
			}

			public String getKeyfile() {
				return key;
			}

			public void authenticationSucceeded() {
			}
		};
	}

	private void testWorkerNode(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_testWorkerNode
		final SshNode node = fillInSshNode();
		final AskUserForPw askUser = fillInAskUser();
		String err = SshUseCaseInvocation.test(node, askUser);
		if (err != null)
			configuration.info.getProgressDisplay().annoyTheUser(err);
		else
			configuration.info.getProgressDisplay().annoyTheUser("Test successful :)");
	}// GEN-LAST:event_testWorkerNode

	private void addWorkerNode(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addWorkerNode
		SshNode node = fillInSshNode();
		configuration.sshWorkerNodes.add(node);
		sshNodesListModel.addElement(node.getHost());
	}// GEN-LAST:event_addWorkerNode

	private void removeAllGridJobs(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_removeAllGridJobs
		configuration.info.cleanHistory();
	}// GEN-LAST:event_removeAllGridJobs

	private void selectKeyfile(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_selectKeyfile
		sshKeyfile.setText(configuration.chooseKeyfile(this));
	}// GEN-LAST:event_selectKeyfile

	private DefaultListModel gridInfosystemListModel;
	private DefaultListModel sshNodesListModel;

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JTextPane authorizedResources;
	private javax.swing.JLabel caFilePath;
	private javax.swing.JLabel certificateIdentity;
	private javax.swing.JList gridInfosystemList;
	private javax.swing.ButtonGroup invocationMethod;
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton10;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JButton jButton4;
	private javax.swing.JButton jButton5;
	private javax.swing.JButton jButton6;
	private javax.swing.JButton jButton7;
	private javax.swing.JButton jButton8;
	private javax.swing.JButton jButton9;
	private javax.swing.JComboBox jComboBox1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel10;
	private javax.swing.JLabel jLabel11;
	private javax.swing.JLabel jLabel12;
	private javax.swing.JLabel jLabel13;
	private javax.swing.JLabel jLabel14;
	private javax.swing.JLabel jLabel15;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JList jList1;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel10;
	private javax.swing.JPanel jPanel11;
	private javax.swing.JPanel jPanel12;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JPanel jPanel5;
	private javax.swing.JPanel jPanel6;
	private javax.swing.JPanel jPanel7;
	private javax.swing.JPanel jPanel8;
	private javax.swing.JPanel jPanel9;
	private javax.swing.JRadioButton jRadioButton1;
	private javax.swing.JRadioButton jRadioButton2;
	private javax.swing.JRadioButton jRadioButton3;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JScrollPane jScrollPane4;
	private javax.swing.JTabbedPane jTabbedPane1;
	private javax.swing.JTabbedPane jTabbedPane2;
	private javax.swing.JTabbedPane jTabbedPane3;
	private javax.swing.JTextPane jTextPane1;
	private javax.swing.JTextField newInfosystemUrl;
	private javax.swing.JTextField sshDir;
	private javax.swing.JTextField sshHostname;
	private javax.swing.JTextField sshKeyfile;
	private javax.swing.JPasswordField sshPass;
	private javax.swing.JTextField sshPort;
	private javax.swing.JTextField sshUser;
	// End of variables declaration//GEN-END:variables

}
